import Vue from "vue";
import _ from "lodash";
import Cookies from 'js-cookie'
import moment from "moment";
import download from "./api/system/download";
import requset from "./utils/fetch";
/* 全局变量 */
Vue.prototype.$api = requset;
Vue.prototype.$post = requset.post;
Vue.prototype.$get = requset.get;
Vue.prototype._ = _;
Vue.prototype.$Cookies = Cookies;
Vue.prototype.moment = moment;

Vue.prototype.$download = download;
Vue.prototype.$tj = function(...codes){
  return Array.from(codes).reduce((pre,cur) => pre + this.$t(cur),'')
};
Vue.prototype.$inputEmptyMes = function(code){
  return this.$t(code) + this.$t("app.emptyMes")
};
Vue.prototype.$inputPlease = function(code){
  return this.$t("app.inputPlease") + this.$t(code)
};
Vue.prototype.$selectPlease = function(code){
  return this.$t("app.selectPlease") + this.$t(code)
};

// 深拷贝对象
Vue.prototype.cloneDeep = _.cloneDeep;
//字段是否为空
Vue.prototype.isFieldEmpty = function(field) {
  if (_.isUndefined(field) || _.isNull(field) || field === "") {
    return true;
  }
  return false;
};

Vue.prototype.isResultEmpty = function(data) {
  if (
    _.isUndefined(data) ||
    _.isNull(data) ||
    data === "" ||
    (_.isArray(data) && data.length === 0) ||
    (_.isObject(data) && _.isEmpty(data))
  ) {
    return true;
  }
  return false;
};

Vue.prototype.getHeight = function(window, otherHeight) {
  if (otherHeight) {
    return window.innerHeight - 50 - 50 - 70 - otherHeight;
  } else {
    return window.innerHeight - 50 - 50  - 70;
  }
};

Vue.prototype.calcHeight = function(otherHeight) {
  if (otherHeight) {
    return window.innerHeight - 50 - 50 - 30 - otherHeight;
  } else {
    return window.innerHeight - 50 - 50 - 30;
  }
};
